<template>
  <div class="aaaa" id="app">
    <img
      shape="square"
      :src="require(`@/icons/svgese/营昕居桌面logo.svg`)"
      style="width: 30px; height: 30px"
    />

    <span class="hconpen" v-if="this.lastname == 'cms'">营昕居后台管理系统</span>
    <span class="hconpen" v-else>营昕居商户管理系统</span>
    <el-avatar>
      <img v-if="this.lastname == 'cms'" src="@/assets/login/head.png" style="width: 100%; height: 100%" />
      <img v-else-if="this.list.avatar" :src="this.list.avatar" style="width: 100%; height: 100%" />
      <img v-else src="@/assets/login/head.png" style="width: 100%; height: 100%" />

    </el-avatar>
    <el-dropdown :hide-on-click="false">
      <span class="el-dropdown-link">
     营昕居<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu>
        <el-button @click.native="logout">退出登录</el-button>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>
<script>
import { resetRouter } from "@/router";
import {information} from '@/api/login'
import {refund} from '@/api/roles'
export default {
  data() {
    return {
      lastname:'',
      list:'',
      q:{
       index:1,
        size:10000,
        refundType:null
      }
    };
  },
  created(){
     this.loachEak()
  
  },
  methods: {
   async loachEak(){
     this.lastname = this.$cookies.get('name')

      const res = await information()
      this.list = res.data
   
      //  this.lastname = sessionStorage.getItem("name");
      // console.log('74',this.lastname);
      // 未读数
      const rec = await refund(this.q)
        let aa = []
      rec.data.data.forEach(item => {
        if(item.status == 'Approval'){
          return aa.push(item)
        }
      }); 
      if(aa.length != 0){
        this.$cookies.set('final',aa.length)  //存到cookies中
      }
    },
    async logout() {
      // 提醒用户是否真的要退出登录
      this.$confirm("真的要退出登录吗?", "提示", { type: "warning" })
        .then(() => {
          this.$cookies.remove('re-token')
          //  sessionStorage.removeItem('name')
           this.$cookies.remove('name');
          console.log(this.lastname)
          if(this.lastname == 'cms'){
            this.$router.push("/cms")
          }else{
            // location.reload();
              this.$router.push("/")
          }
          // 提醒用户
          this.$message.success("退出登录成功");
          resetRouter();
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped lang="less">
.hconpen {
  position: absolute;
  top: 0;
  font-size: 15px;
  line-height: 45px;
  color: #000;
  font-weight: 500;
  margin-top: 2px;
}
.el-avatar {
  float: right;
  margin-right: 20px;
  width: 35px;
  height: 35px;
}
.el-dropdown {
  position: relative;
  position: absolute;
  right: 90px;
}
.el-avatar--circle {
  position: absolute;
  right: 150px;
}
.el-dropdown-link {
  display: inline-block;
  line-height: 40px;
  font-size: 15px;
}
img {
  margin-right: 10px;

  border-radius: 29%;
}
.el-button {
  border: 1px solid rgba(0, 0, 0, 0);
}

.aaaa{
  padding-left: 30px;
  height: 85%;
}
.el-button--primary{
border-color: rgb(0,0,0,0);
}
</style>
